﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="PlanningFollowup.aspx.cs" Inherits="TireService.Web.View.ServiceView.PlanningFollowup" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    
    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgCustomerFollowup" alt="" src="~/Images/Medium/calendar_preferences.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblCustomerFollowup" runat="server" Text="Opfølgning kundebooking"></asp:Label></h3>
            </td>
        </tr>
    </table>
    <hr />

    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        // Function that handles actions selected in dropdown list
        function ActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {
                
                // Mark selected as approved by customer
                if (id == 1) {
                    // Get selected items in gridview and trigger event MarkSelectedAsApproved
                    gvPlanningFollowup.GetSelectedFieldValues('ServiceCarScheduleDetailId', MarkSelectedAsApproved);
                }

                // Send new approval mail to customer
                if (id ==2) {
                    // Get selected items in gridview and trigger event RequestApprovalSelectedCustomers
                    gvPlanningFollowup.GetSelectedFieldValues('ServiceCarScheduleDetailId', RequestApprovalSelectedCustomers);
                }

            }
            else {
                alert('Ingen handling valgt');
            }
        }

        // Perform callback that updates booked services as customer approved for selected customers/bookings
        function MarkSelectedAsApproved(selectedValues) {

            if (selectedValues.length == 0) return;

            callBackMarkSelectedAsApproved.PerformCallback(selectedValues);
        }

        function OnCallbackMarkSelectedAsApprovedComplete(s, e) {
            
            // Refresh gridviews
            gvPlanningFollowup.PerformCallback();

            alert('Valgte angivet som godkendte');
        }

        // Perform callback that sends request for booking confirmation for selected customers/bookings
        function RequestApprovalSelectedCustomers(selectedValues) {
            if (selectedValues.length == 0) return;

            //var input = "RequestApproval" + '|' + selectedValues.toString().replace(",", "|");
            var input = "RequestApproval" + ',' + selectedValues;
            callBackManageCustomerApproval.PerformCallback(input);
        }

        function CallbackError() {
            alert('Fejl opstod - prøv venligst igen');
        }

        // Function that runs when server side completed processing of handling customer approval action
        function OnCallbackManageCustomerApprovalComplete(s, e) {
            gvPlanningFollowup.PerformCallback();
            
            // Uncheck all rows in gridview
            gvPlanningFollowup.UnselectRows();

            alert('Handling udført');
        }

    </script>

    <dx:ASPxCallback ID="callBackMarkSelectedAsApproved" ClientInstanceName="callBackMarkSelectedAsApproved" runat="server" OnCallback="callBackMarkSelectedAsApproved_Callback">
        <ClientSideEvents CallbackError="CallbackError" CallbackComplete="OnCallbackMarkSelectedAsApprovedComplete" />
    </dx:ASPxCallback>

    <dx:ASPxCallback ID="callBackManageCustomerApproval" ClientInstanceName="callBackManageCustomerApproval" runat="server" OnCallback="callBackManageCustomerApproval_Callback">
        <ClientSideEvents CallbackError="CallbackError" CallbackComplete="OnCallbackManageCustomerApprovalComplete" />
    </dx:ASPxCallback>

    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dxe:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dxe:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                        <dxe:ListEditItem Value="1" Text="Angiv som godkendt" />
                        <dxe:ListEditItem Value="2" Text="Send booking mail" />
                    </Items>
                </dxe:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dxe:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dxe:ASPxButton>
            </td>
            <td style="width:150px">
                <dxe:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dxe:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dxe:ListEditItem Value="1" Text="Export xls" />
                        <dxe:ListEditItem Value="2" Text="Export csv" />
                        <dxe:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dxe:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dxe:ASPxButton ID="btnExport" runat="server" Text="Exporter" OnClick="btnExport_Click" Width="75px" >
                </dxe:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:DropDownList ID="ddlView" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddlView_SelectedIndexChanged">
                    <asp:ListItem Value="0">Grupper efter Dato og bil</asp:ListItem>
                    <asp:ListItem Value="1">Grupper efter Lager og Dato</asp:ListItem>
                </asp:DropDownList>
                &nbsp;
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
    </table>          
    <hr />        

    <dxwgv:ASPxGridView ID="gvPlanningFollowup" runat="server" ClientInstanceName="gvPlanningFollowup" 
        KeyFieldName="ServiceCarScheduleDetailId" Width="100%" AutoGenerateColumns="False" EnableCallBacks="True" 
        oncustomunboundcolumndata="gvPlanningFollowup_CustomUnboundColumnData" 
        oncustombuttoncallback="gvPlanningFollowup_CustomButtonCallback" 
        onrowdeleting="gvPlanningFollowup_RowDeleting">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Border BorderWidth="0px" />
        <SettingsText ConfirmDelete="Vil du slette dette planlagte hjulskift?" />
        <Settings ShowHeaderFilterButton="False" ShowGroupPanel="false" ShowFilterRow="False" />
        <SettingsPager AlwaysShowPager="False" PageSize="20" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} hjulskift)" 
                Text="Side {0} af {1} ({2} hjulskift)" />
        </SettingsPager>
        <SettingsBehavior AllowFocusedRow="false" ConfirmDelete="True" AllowGroup="true" AllowDragDrop="false" />
        <Columns>
            <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvPlanningFollowup.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dxwgv:GridViewCommandColumn>
            <dxwgv:GridViewCommandColumn VisibleIndex="1">
                <DeleteButton Text="Slet" Visible="true" />
                <CustomButtons>
                    <dxwgv:GridViewCommandColumnCustomButton Text="Godkend" ID="Approve" />
                </CustomButtons>
            </dxwgv:GridViewCommandColumn>
            <dxwgv:GridViewDataHyperLinkColumn FieldName="CustomerId" VisibleIndex="2" Caption="Navn">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomerData.aspx?CustomerId={0}" TextField="Name">
                </PropertiesHyperLinkEdit>
            </dxwgv:GridViewDataHyperLinkColumn>
            <dxwgv:GridViewDataColumn FieldName="CarId" Visible="false" VisibleIndex="4" Caption="CarId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CustomerId" Visible="false" VisibleIndex="4" Caption="CustomerId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireSetId" Visible="false" VisibleIndex="4" Caption="TireSetId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="SubscriptionId" Visible="false" VisibleIndex="4" Caption="SubscriptionId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ContainerId" Visible="false" VisibleIndex="4" Caption="ContainerId">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ScheduleDate" VisibleIndex="4" Caption="ScheduleDate">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="ContainerNumber" VisibleIndex="4" Caption="ContainerNumber">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataTextColumn FieldName="ServiceCarId" VisibleIndex="4" Caption="Servicebil">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataColumn FieldName="SequenceNumber" VisibleIndex="4" Caption="Sekvensnr">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataTextColumn FieldName="CargoRoomNumber" VisibleIndex="5" Caption="Lagerplads">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataColumn FieldName="Name" VisibleIndex="4" Caption="Navn">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="CustomerEmailSendCount" VisibleIndex="4" Caption="Påmindelser">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Phone1" VisibleIndex="4" Caption="Telefon1">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="Phone2" VisibleIndex="4" Caption="Telefon2">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataTextColumn FieldName="StartTime" VisibleIndex="5" Caption="Start">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="EndTime" VisibleIndex="5" Caption="Slut">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="ToAddress" VisibleIndex="5" Caption="Adresse">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="ToZipCode" VisibleIndex="5" Caption="Postnr">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="ToCity" VisibleIndex="5" Caption="By">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataTextColumn FieldName="CarBrandDescription" VisibleIndex="6" Caption="Bilmærke">
            </dxwgv:GridViewDataTextColumn>
            <dxwgv:GridViewDataColumn FieldName="Model" VisibleIndex="7" Caption="Model">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="8" Caption="Reg.nr.">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireTypeDescription" VisibleIndex="9" Caption="Type">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="TireBrandDescription" VisibleIndex="10" Caption="Dækmærke">
            </dxwgv:GridViewDataColumn>
            <dxwgv:GridViewDataColumn FieldName="DummyTireSet" VisibleIndex="12" ToolTip="Angiver om dette er et dummy hjulsæt pga. vi endnu ikke har været ude ved kunden og fået hjul med hjem" Caption="Dummy">
            </dxwgv:GridViewDataColumn>
        </Columns>                                            
    </dxwgv:ASPxGridView>            
                
    <dxwgv:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvPlanningFollowup">
    </dxwgv:ASPxGridViewExporter>

</asp:Content>

